package com.wuzhuo.information.service.serviceImpl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.wuzhuo.information.pojo.Message;
import com.wuzhuo.information.pojo.Messages;
import com.wuzhuo.information.pojo.PageBean;
import com.wuzhuo.information.pojo.User;
import com.wuzhuo.information.service.messageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.wuzhuo.information.mapper.messageMapper;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@Service
public class messageServiceImpl implements messageService {

    @Autowired
    private messageMapper messageMapper;

    @Override
    public List<Message> page(String addressee) {
//        PageHelper.startPage(page, pageSize);
////        System.out.println("================="+addressee+"============================");
        List<Message> messageList = messageMapper.list(addressee);
//        Page<Message> p = (Page<Message>) messageList;
//        PageBean pageBean = new PageBean(p.getTotal(), p.getResult());
        return messageList;
    }

    @Override
    public void delete(List<Long> ids) {
        messageMapper.deleteById(ids);
    }

    @Override
    public Message getMessageById(Integer id) {
        Message message = messageMapper.getMessageById(id);
        messageMapper.changeRead(id);
        return message;
    }

    @Override
    public void addMessage(Message message) {
        message.setDate(LocalDate.now());
        messageMapper.insert(message);
    }

    @Override
    public void replyMessages(Messages messages) {
        System.out.println("================="+messages.getAddressee()+"==============");
        Message message = new Message();
        message.setContent(messages.getContent());
        message.setAll(messages.getAll());
        message.setRemark(messages.getRemark());
        message.setName(messages.getName());
        message.setTitle(messages.getTitle());
        message.setDate(LocalDate.now());
        for (int i = 0; i < messages.getAddressee().size(); i++) {
            message.setAddressee(messages.getAddressee().get(i));
            messageMapper.reply(message);
        }
    }

}
